Skip to main content
Version: 1.0.0

newCatalogueHasBeenPublished

New Catalogue Published Template

Function Name: newCatalogueHasBeenPublished

Author: Domenico Cerone Creation Date: 25/09/2025
Last Reviewer: Domenico Cerone

Trigger: HTTPS (onRequest)

Purpose: Sends notification when a new catalog is added to a license. Notifies users with access to the catalog, main profiles, and administrators through ZeptoMail template with catalog and license details.

Detailed Functionalityโ€‹

1. REQUEST VALIDATIONโ€‹

  • Validates presence of required parameters: catalogId and licenseId
  • Returns error if either parameter is missing

2. CATALOG DATA RETRIEVALโ€‹

  • Queries 'Catalogues' collection using provided catalogId
  • Retrieves catalog information including nameCatalog and webDomain
  • Validates catalog existence

3. LICENSE DATA RETRIEVALโ€‹

  • Queries 'ARShadesSubscriptions' collection using provided licenseId
  • Retrieves license information including clientRef, name, subscriptionType, and list_catalogues
  • Validates license existence

4. CLIENT DATA RETRIEVALโ€‹

  • Queries 'Client' collection using clientRef from license
  • Retrieves client information including allProfileList and mainProfileList
  • Validates client existence

5. NOTIFICATION PREFERENCE CHECKโ€‹

  • For each profile in allProfileList, checks if newCatalogueHasBeenPublished notification is enabled
  • Verifies notification_types.newCatalogueHasBeenPublished field in each profile
  • If notification is disabled (false): skips that profile without sending email
  • If notification is enabled (true): proceeds with catalog access verification
  • Provides clear logging about notification preference status for each profile

6. RECIPIENTS SELECTION - TO (PRIMARY)โ€‹

  • Iterates through all profiles in allProfileList
  • For each profile, checks if list_catalogues includes the catalogId
  • Adds profiles with catalog access to TO recipients list
  • Uses email prefix as display name

7. RECIPIENTS SELECTION - CC (MAIN PROFILES)โ€‹

  • Adds all emails from mainProfileList to CC recipients
  • Uses email prefix as display name
  • Ensures main profiles are always notified regardless of catalog access

8. RECIPIENTS SELECTION - BCC (ADMINS)โ€‹

  • Queries 'Profiles' collection for all users with role = 'Admin'
  • Adds all admin profiles to BCC recipients
  • Uses email prefix as display name

9. EMAIL DATA PREPARATIONโ€‹

  • Prepares merge data for ZeptoMail template:
    • name: Catalog name (catalogData.nameCatalog)
    • number3dAsset: SKU limit (uses 5000 if skuLimit is 0)
    • licenseName: Combined license name and subscription type
    • catalogueLink: Direct link to catalog with domain and catalog ID
    • licenseLink: Link to license management (temporary value)

10. EMAIL SENDING WITH ZEPTOMAILโ€‹

  • Uses dedicated template key for catalog publication notifications (MAIL_TEMPLATE_KEY: 13ef.8598f19fbcc5adb.k1.b3895820-4833-11f0-900d-dad70ff08860.197687d56a2)
  • Sends to three recipient types: TO (catalog users), CC (main profiles), BCC (admins)
  • Includes all merge data for template personalization

11. RESPONSE HANDLINGโ€‹

  • Returns success response with catalog and license details
  • Includes generated links for reference
  • Handles and logs any errors during processing

Input (Payload)โ€‹

Method: POST

Headers:

  • Content-Type: application/json

Body:

{
"catalogId": "4RAmQ13cjXo7ns1nmOOT",
"licenseId": "pkq5xTkMAIl4KiQxsFlB"
}

Parameters:

  • catalogId (string, required): Unique identifier of the catalog
  • licenseId (string, required): Unique identifier of the license

Output (Success)โ€‹

{
"success": true,
"message": "Notifications sent successfully",
"catalogName": "POLAROID SS25 - FW24",
"number3dAsset": 5000,
"licenseName": "ARShades Pro - Standard",
"catalogueLink": "https://www.example.com/?c=4RAmQ13cjXo7ns1nmOOT",
"licenseLink": "http://studio.arshades.it/xxx"
}

Response Properties:

  • success (boolean): Indicates if the operation was completed successfully
  • message (string): Descriptive message about the operation result
  • catalogName (string): Name of the published catalog
  • number3dAsset (number): Number of 3D assets allowed (SKU limit or 5000 default)
  • licenseName (string): Full license name with subscription type
  • catalogueLink (string): Direct URL to access the catalog
  • licenseLink (string): URL to license management interface

Testingโ€‹

URL (if HTTPS): http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished

Test with Emulator:

  1. Avviare l'emulatore Firebase: firebase emulators:start --only functions
  2. Assicurarsi di usare Node.js versione 20: nvm use 20
  3. Testare con curl:
curl -X POST "http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished" \
-H "Content-Type: application/json" \
-d '{
"catalogId": "4RAmQ13cjXo7ns1nmOOT",
"licenseId": "pkq5xTkMAIl4KiQxsFlB"
}'

Postman Testing:

  • Metodo: POST
  • URL: http://127.0.0.1:5001/arshadesstaging/europe-central2/newCatalogueHasBeenPublished
  • Headers:
    • Key: Content-Type
    • Value: application/json
  • Body: raw JSON (vedi esempi sopra)

Deploy Commandโ€‹

firebase deploy --only functions:newCatalogueHasBeenPublished

URL di Produzioneโ€‹

newCatalogueHasBeenPublished: https://europe-central2-arshades-7e18a.cloudfunctions.net/newCatalogueHasBeenPublished